package cn.ac.iie.di.ban.jr.rest.config;

import org.apache.commons.configuration2.FileBasedConfiguration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Parameters;
import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.log4j.Logger;

public class ConfigureUtil {

    public static Logger LOG = Logger.getLogger(ConfigureUtil.class);

    public FileBasedConfiguration initConfiguration(String PATH) throws ConfigurationException {
            Parameters params = new Parameters();
            FileBasedConfigurationBuilder<FileBasedConfiguration> confBuilder
                    = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
                    PropertiesConfiguration.class)
                    .configure(params.properties()
                            .setFileName(PATH)
                            .setListDelimiterHandler(new DefaultListDelimiterHandler(','))
                            .setThrowExceptionOnMissing(true));
            FileBasedConfiguration configuration = confBuilder.getConfiguration();
            return configuration;
    }
}
